/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.cnam.mobileShopping.entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Administrateur
 */
@Entity
@Table(name = "product",catalog = "mobileshopping", schema = "public")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Product.findAll", query = "SELECT p FROM Product p"),
    @NamedQuery(name = "Product.findByProductid", query = "SELECT p FROM Product p WHERE p.productid = :productid"),
    @NamedQuery(name = "Product.findByDescription", query = "SELECT p FROM Product p WHERE p.description = :description"),
    @NamedQuery(name = "Product.findByBarcode", query = "SELECT p FROM Product p WHERE p.barcode = :barcode"),
    @NamedQuery(name = "Product.findAfterDate", query = "SELECT p FROM Product p WHERE p.lastupdatedatetime > :lastupdate"),
    @NamedQuery(name = "Product.findByCategory", query = "SELECT p FROM Product p WHERE p.categoryid = :categoryid")})
@XmlAccessorType(XmlAccessType.PUBLIC_MEMBER)
public class Product implements Serializable {
    private static final long serialVersionUID = -2180140545784020807L;  
   
    private Integer productid;
       
    private String description;
    
    private String barcode;
    
    private Category categoryid;
    
    private Date lastupdatedatetime;

    

    public Product() {
    }

    public Product(Integer productid) {
        this.productid = productid;
    }

    @Id
    @Basic(optional = false)
    @Column(name = "productid")
    @XmlElement(name="id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public Integer getProductid() {
        return productid;
    }

    public void setProductid(Integer productid) {
        this.productid = productid;
    }
    
    @Column(name = "description")
    @XmlElement(name="description")
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Column(name = "barcode")
    @XmlElement(name="barcode")
    public String getBarcode() {
        return barcode;
    }

    public void setBarcode(String barcode) {
        this.barcode = barcode;
    }

    @JoinColumn(name = "categoryid", referencedColumnName = "categoryid")
    @ManyToOne
    @XmlTransient
    public Category getCategoryid() {
        return categoryid;
    }
    
    @XmlElement(name="categoryId")
    public Integer getCategoryIdentifiant() {
        return categoryid.getCategoryid();
    }

    public void setCategoryid(Category categoryid) {
        this.categoryid = categoryid;
    }
    
    @Column(name = "lastupdatedatetime")
    @XmlTransient
    @Temporal(javax.persistence.TemporalType.DATE)
    public Date getLastupdatedatetime() {
        return lastupdatedatetime;
    }

    public void setLastupdatedatetime(Date lastupdatedatetime) {
        this.lastupdatedatetime = lastupdatedatetime;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (productid != null ? productid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Product)) {
            return false;
        }
        Product other = (Product) object;
        if ((this.productid == null && other.productid != null) || (this.productid != null && !this.productid.equals(other.productid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.cnam.mobileShopping.entity.Product[ productid=" + productid + " ]";
    }

}
